package com.awspaas.user.apps.cpq.event;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListener;
import com.actionsoft.sdk.local.SDK;

public class ApprovalTaskBeforeComplete extends InterruptListener{

	public ApprovalTaskBeforeComplete() {
		setDescription("项目报价审批流程办理后，将项目报价数据状态进行更新");
	}

	@Override
	public boolean execute(ProcessExecutionContext pec) throws Exception {
		try {
			boolean is=	pec.isChoiceActionMenu("同意");
			if(!is) {
				return true;	
			}
			String  bindId=pec.getProcessInstance().getId();
			BO data=SDK.getBOAPI().query("BO_EU_CPQ_APPROVAL_P").bindId(bindId).detail();
			String type=data.getString("LX");
			String pid=data.getString("GLBJD");
			String status="";
			if(type.equals("报价模板发布")) {
				status="启用";
			}else if (type.equals("报价模板变更")) {
				status="拟制";
			}else if (type.equals("报价模板停用")) {
				status="停用";
			}else if (type.equals("项目报价审核")) {
				status="启用";
			}else if (type.equals("配件报价审核")) {
				status="启用";
			}
			
			
			if(!status.isEmpty()) {
				if(type.equals("配件报价审核")) {
					SDK.getBOAPI().updateByBindId("BO_EU_CPQ_AFTER_SALES", pid, "FLOWSTATUS", status);	
				}else {
					SDK.getBOAPI().updateByBindId("BO_EU_CPQ_PROJECT_MSG", pid, "FLOWSTATUS", status);	
				}
				
			}
			return true;
		} catch (Exception e) {
			throw e;
		}
		
	}

}
